#ifndef _MINBASICLIB_LOGGER_LOGGER_H_
#define _MINBASICLIB_LOGGER_LOGGER_H_

#include <syslog.h>

#include <global/types.h>
#include <global/const.h>

typedef int t_loglevel;

typedef enum {
	None = 0,
	CutByTime = 1,
	CutBySize = 2,
	RollByTime = 3,
	RollBySize = 4
} t_logcut;

typedef struct {
	char ln[MAXFULLFILENAME];	// log name
	t_fd fd;
	t_loglevel level;
	t_logcut cut;
	long cutp;			// cut param
	long cutp1;			// cut param 1
	long cutp2;			// cut param 2
	long cutp3;			// cut param 3
} t_log;

extern t_log * glog;

t_log * log_create(const char * fn);

void log_setglog(t_log * log);

t_log * log_getglog();

// cutp == current time (auto set)
// cutp1 == time block
// cutp2 == unused
// cutp3 == unused
t_log * log_create_cbt(const char * fn, long cutp1);

// cutp == size block
// cutp1 == next suffix
// cutp2 == unused
// cutp3 == unused
t_log * log_create_cbs(const char * fn, long cutp);

// cutp == current time (auto set)
// cutp1 == time block
// cutp2 == max num
// cutp3 == next suffix
t_log * log_create_rbt(const char * fn, long cutp1, long cutp2);

// cutp == size block
// cutp1 == max num
// cutp2 == next suffix
// cutp3 == unused
t_log * log_create_rbs(const char * fn, long cutp, long cutp1);

t_log * log_create_cut(const char * fn, t_logcut cut, long cutp, long cutp1, long cutp2, long cutp3);

void log_destroy(t_log * plog);

void log_level(t_log * plog, t_loglevel level);

t_fd log_fd(t_log * plog);

int log_write(t_log * plog, const char * fmt, ...);

#endif
